/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021.
 * Description: add ubifs debug information funcitons
 * Author: liangfangping <liangfangping@huawei.com>
 * Create: 2021-05-07
 */
#include "rtos_ubifs_debug.h"
#include "ubifs.h"

/**
 * ubifs_dump_ubifs_info - dump the ubifs_info.
 * @c: UBIFS file-system description object
 *
 * This function dumps the ubifs_info structure.
 */
void ubifs_dump_ubifs_info(struct ubifs_info *c)
{
	long long x;

	rtos_ubifs_msg("default compressor:  %s",
		ubifs_compr_name(c, c->default_compr));
	rtos_ubifs_msg("data journal heads:  %d",
		c->jhead_cnt - NONDATA_JHEADS_CNT);
	rtos_ubifs_msg("log LEBs:            %d (%d - %d)",
		c->log_lebs, UBIFS_LOG_LNUM, c->log_last);
	rtos_ubifs_msg("LPT area LEBs:       %d (%d - %d)",
		c->lpt_lebs, c->lpt_first, c->lpt_last);
	rtos_ubifs_msg("orphan area LEBs:    %d (%d - %d)",
		c->orph_lebs, c->orph_first, c->orph_last);
	rtos_ubifs_msg("main area LEBs:      %d (%d - %d)",
		c->main_lebs, c->main_first, c->leb_cnt - 1);
	rtos_ubifs_msg("index LEBs:          %d", c->lst.idx_lebs);
	rtos_ubifs_msg("total index bytes:   %llu (%llu KiB, %llu MiB)",
		c->bi.old_idx_sz, c->bi.old_idx_sz >> 10,
		c->bi.old_idx_sz >> 20);
	rtos_ubifs_msg("key hash type:       %d", c->key_hash_type);
	rtos_ubifs_msg("tree fanout:         %d", c->fanout);
	rtos_ubifs_msg("reserved GC LEB:     %d", c->gc_lnum);
	rtos_ubifs_msg("max. znode size      %d", c->max_znode_sz);
	rtos_ubifs_msg("max. index node size %d", c->max_idx_node_sz);
	rtos_ubifs_msg("node sizes:          data %zu, inode %zu, dentry %zu",
		UBIFS_DATA_NODE_SZ, UBIFS_INO_NODE_SZ, UBIFS_DENT_NODE_SZ);
	rtos_ubifs_msg("node sizes:          trun %zu, sb %zu, master %zu",
		UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ);
	rtos_ubifs_msg("node sizes:          ref %zu, cmt. start %zu, orph %zu",
		UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ);
	rtos_ubifs_msg("max. node sizes:data %zu, inode %zu dentry %zu, idx %d",
		UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ,
		UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout));
	rtos_ubifs_msg("dead watermark:      %d", c->dead_wm);
	rtos_ubifs_msg("dark watermark:      %d", c->dark_wm);
	rtos_ubifs_msg("LEB overhead:        %d", c->leb_overhead);
	x = (long long)c->main_lebs * c->dark_wm;
	rtos_ubifs_msg("max. dark space:     %lld (%llu KiB, %llu MiB)",
		x, (unsigned long long)x >> 10, (unsigned long long)x >> 20);
	rtos_ubifs_msg("maximum bud bytes:   %lld (%llu KiB, %llu MiB)",
		c->max_bud_bytes, (unsigned long long)c->max_bud_bytes >> 10,
		(unsigned long long)c->max_bud_bytes >> 20);
	rtos_ubifs_msg("BG commit bud bytes: %lld (%llu KiB, %llu MiB)",
		c->bg_bud_bytes, (unsigned long long)c->bg_bud_bytes >> 10,
		(unsigned long long)c->bg_bud_bytes >> 20);
	rtos_ubifs_msg("current bud bytes    %lld (%llu KiB, %llu MiB)",
		c->bud_bytes, (unsigned long long)c->bud_bytes >> 10,
		(unsigned long long)c->bud_bytes >> 20);
	rtos_ubifs_msg("max. seq. number:    %llu", c->max_sqnum);
	rtos_ubifs_msg("commit number:       %llu", c->cmt_no);
	rtos_ubifs_msg("max. xattrs per inode: %d", ubifs_xattr_max_cnt(c));
	rtos_ubifs_msg("max orphans:           %d", c->max_orphans);
}

/**
 * ubifs_dump_bud_info - dump the budget info.
 * @c: UBIFS file-system description object
 *
 * This function dumps the ubifs_budg_info structure.
 */
void ubifs_dump_budg_info(struct ubifs_info *c)
{
	rtos_ubifs_msg("idx_growth %lld", c->bi.idx_growth);
	rtos_ubifs_msg("data_growth %lld", c->bi.data_growth);
	rtos_ubifs_msg("dd_growth %lld", c->bi.dd_growth);
	rtos_ubifs_msg("uncommitted_idx %lld", c->bi.uncommitted_idx);
	rtos_ubifs_msg("old_idx_sz %llu", c->bi.old_idx_sz);
	rtos_ubifs_msg("min_idx_lebs %d", c->bi.min_idx_lebs);
	rtos_ubifs_msg("nospace %u", c->bi.nospace);
	rtos_ubifs_msg("nospace_rp %u", c->bi.nospace_rp);
	rtos_ubifs_msg("page_budget %d", c->bi.page_budget);
	rtos_ubifs_msg("inode_budget %d", c->bi.inode_budget);
	rtos_ubifs_msg("dent_budget %d", c->bi.dent_budget);
}

/**
 * ubifs_dump_bud_info - dump the budget info.
 * @c: UBIFS file-system description object
 *
 * This function dumps the ubifs_budg_info structure.
 */
void ubifs_dump_ubifs_lpt_info(const struct ubifs_info *c)
{
	rtos_ubifs_msg("space_bits %d", c->space_bits);
	rtos_ubifs_msg("lpt_lnum_bits %d", c->lpt_lnum_bits);
	rtos_ubifs_msg("lpt_offs_bits %d", c->lpt_offs_bits);
	rtos_ubifs_msg("lpt_spc_bits %d", c->lpt_spc_bits);
	rtos_ubifs_msg("pcnt_bits %d", c->pcnt_bits);
	rtos_ubifs_msg("lnum_bits %d", c->lnum_bits);
	rtos_ubifs_msg("pnode_sz %d", c->pnode_sz);
	rtos_ubifs_msg("nnode_sz %d", c->nnode_sz);
	rtos_ubifs_msg("ltab_sz %d", c->ltab_sz);
	rtos_ubifs_msg("lsave_sz %d", c->lsave_sz);
	rtos_ubifs_msg("lsave_cnt %d", c->lsave_cnt);
	rtos_ubifs_msg("lpt_hght %d", c->lpt_hght);
	rtos_ubifs_msg("big_lpt %u", c->big_lpt);
	rtos_ubifs_msg("LPT root is at %d:%d", c->lpt_lnum, c->lpt_offs);
	rtos_ubifs_msg("LPT head is at %d:%d", c->nhead_lnum, c->nhead_offs);
	rtos_ubifs_msg("LPT ltab is at %d:%d", c->ltab_lnum, c->ltab_offs);
	if (c->big_lpt)
		rtos_ubifs_msg("LPT lsave is at %d:%d",
			c->lsave_lnum, c->lsave_offs);
}
